# Maintainer: Johannes Marbach <n0-0ne+gitlab@mailbox.org>
pkgname=unl0kr
pkgver=3.2.0
pkgrel=5
_commit_lvgl=ceadda8a468b7d5fa6ba973bd82cf610166278d8
pkgdesc="Framebuffer-based disk unlocker for the initramfs based on LVGL"
url="https://gitlab.postmarketos.org/postmarketOS/buffybox"
arch="all"
license="GPL-3.0-or-later"
depends="
	cryptsetup
	inih
	libdrm
	libinput-libs
	libxkbcommon
	"
makedepends="
	eudev-dev
	inih-dev
	libdrm-dev
	libinput-dev
	libxkbcommon-dev
	linux-headers
	meson
	scdoc
	"
source="
	https://gitlab.postmarketos.org/postmarketOS/buffybox/-/archive/$pkgver/buffybox-$pkgver.tar.gz
	lvgl-$_commit_lvgl.tar.gz::https://github.com/lvgl/lvgl/archive/$_commit_lvgl.tar.gz
	unl0kr.conf
	unl0kr.files
	unlock.sh
	30-unl0kr-test.sh
	"
options="!check" # No tests
# "providing" osk-sdl, since it was dropped from pmaports
provides="postmarketos-fde-unlocker osk-sdl=$pkgver-r$pkgrel"
provider_priority=1000
subpackages="$pkgname-doc $pkgname-pmtest"
builddir="$srcdir/buffybox-$pkgver/unl0kr"

prepare() {
	default_prepare
	mkdir -p ../lvgl
	mv "$srcdir/lvgl-$_commit_lvgl"/* ../lvgl
}

build() {
	abuild-meson build
	meson compile ${JOBS:+-j ${JOBS}} -C build
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C build

	install -Dm644 "$srcdir"/unl0kr.conf \
		"$pkgdir"/etc/unl0kr.conf

	install -Dm755 "$srcdir"/unlock.sh \
		"$pkgdir"/usr/bin/fde-unlock

	touch unl0kr
	install -Dm644 unl0kr \
		"$pkgdir"/usr/share/mkinitfs-triggers/unl0kr

	# TODO: Figure out why this is needed
	touch dummy
	install -Dm644 dummy \
		"$pkgdir"/etc/unl0kr.conf.d/dummy

	install -Dm644 "$srcdir"/unl0kr.files \
		"$pkgdir"/usr/share/mkinitfs/files-extra/30-unl0kr.files
}

pmtest() {
	install_if="$pkgname=$pkgver-r$pkgrel postmarketos-mkinitfs-hook-ci"

	install -Dm755 "$srcdir"/30-unl0kr-test.sh \
		"$subpkgdir"/usr/libexec/pmos-tests-initramfs/30-unl0kr-test.sh

	# We need the files in the core initramfs for this, no -extra in CI
	install -Dm644 "$srcdir"/unl0kr.files \
		"$subpkgdir"/usr/share/mkinitfs/files/30-unl0kr.files
}
sha512sums="
83d6724750e6f7e048063863e78251d32a23b1c7aa9e3529a0b176c415bda70c91b83924f6a71cc7f5ca29f019e7a974b406f6e83ff038dae92430b53183d5fa  buffybox-3.2.0.tar.gz
d3611fe9d55ed105d9567b6019dc49fc0510ac4ed6ca6e15ba0c1bae47f2833d8784b3e008a4dec76dce55bf3809531d07c62e4ba24bafad69c6c54fdd0b70c0  lvgl-ceadda8a468b7d5fa6ba973bd82cf610166278d8.tar.gz
7155c2f95dcf3716c0f392cf5717e96f1414c383a1f7c2ed30a1f8518dfe0b17c3c0e0e93f6476a342504aa855404099e2f5444eeb099023491c9a9a26fa3d90  unl0kr.conf
b57260da131a4f40a0a3ee045e8394d4ab79caede9926d77f241afe79c1813fa77f4e312fa3b5e2e5c9fc1b9af082e7c59717abdaf30d512a7eb838a5f623ef8  unl0kr.files
5386f434cd4f1fb9e0d561a8689e5e85d6a8b3c562823122c082d4932d2fb0ad4edcd635f14f0c61e5c8b5e53648c9937b042409c21683007700faea8894c750  unlock.sh
407180b49c1a05f12bd6ee6e59dca0a6e74fe7b01f195087dcf2865598c47827d0bb569afdba55defa2f9a16437230fa62aa64f35111508b906bcbf9537acba4  30-unl0kr-test.sh
"
